/*============================================================================
  File:      DmhMemory.cpp
 
  Summary:   Implementation of helper classes and functions for allocating memory

  Date:		 June 30, 2004
------------------------------------------------------------------------------
  This file is part of the Microsoft SQL Server Code Samples.
 
  Copyright (C) 2003 Microsoft Corporation.  All rights reserved.
 
This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.
 
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
============================================================================*/

#include "stdafx.h"
#include "DmhMemory.h" 

HRESULT	DMHALLOC::SetAllocator(IDMServices* pidmservices)
{
	return pidmservices->GetGeneralAlloc(&_spidmmemoryallocator);
}

HRESULT	DMHALLOC::SetAllocator(IDMMemoryAllocator* pidmmemoryallocator)
{
	_spidmmemoryallocator = pidmmemoryallocator;

	return S_OK;
}

HRESULT	DMHALLOC::SetAllocator(DMHALLOC& dmhalloc)
{
	_spidmmemoryallocator = dmhalloc._spidmmemoryallocator;

	return S_OK;
}
	
void* operator new(size_t sizet, DMHALLOC& dmhalloc)
{
	byte* pbyte;

	HRESULT hr = dmhalloc._spidmmemoryallocator->Alloc((UINT) sizet, &pbyte);

	if (!SUCCEEDED(hr))
	{
		return NULL;
	}

	return (void*) pbyte;
}

void operator delete(void* pv, DMHALLOC& dmhalloc)
{
	dmhalloc._spidmmemoryallocator->Free((byte*) pv);
}


	
	